package order.dao;

import order.pojo.admin;
import order.pojo.customer;
import order.pojo.manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class loginDao {
    //查出管理员的账号密码
    public List<admin> querryAlladmin(Connection con,admin Admin) throws SQLException {
        ArrayList<admin> adminlist = new ArrayList<>();
        String sql="select * from admin ";
        PreparedStatement pstm=con.prepareStatement(sql);
        ResultSet rs=pstm.executeQuery();
        while(rs.next()){
            admin admin = new admin();
            admin.setAdmin_id(rs.getString("admin_id"));
            admin.setAdmin_password(rs.getString("admin_password"));
adminlist.add(admin);

        }
return adminlist;


    }
    //查找一个管理员
    public admin selectAdminBtId(Connection con) throws SQLException {
        ArrayList<admin> adminlist = new ArrayList<>();
        String sql = "select * from admin where admin_id= 'admin'   ";
        PreparedStatement pstm = con.prepareStatement(sql);
        ResultSet rs = pstm.executeQuery();
        admin admin = null;
        while (rs.next()) {
            admin = new admin();
            admin.setAdmin_id(rs.getString("admin_id"));
            admin.setAdmin_password(rs.getString("admin_password"));



        }
        return admin;
    }
    //店家登陆
    public manager managerLogin(Connection con) throws SQLException {

        String sql = "select * from manager where manager_id= 1  ";
        PreparedStatement pstm = con.prepareStatement(sql);
        ResultSet rs = pstm.executeQuery();
        manager manager = null;
        while (rs.next()) {
           manager = new manager();
           manager.setManager_id(rs.getInt("manager_id"));
           manager.setManager_account(rs.getString("manager_account"));
           manager.setManager_password(rs.getString("manager_password"));


          ;

        }
        return manager;


    }
    //顾客登陆

    public customer customerLogin(Connection con) throws SQLException {
        String sql = "select * from customer where customer_id= 1   ";
        PreparedStatement pstm = con.prepareStatement(sql);
        ResultSet rs = pstm.executeQuery();
        customer customer =new customer();
        while (rs.next()) {
            customer.setCustomer_id(rs.getInt("customer_id"));
          customer.setCustomer_account(rs.getString("customer_account"));
          customer.setCustomer_password(rs.getString("customer_password"));




        }
        return customer;


    }

}
